Skip list "find" function

Hello everybody.

I have a very strange behaviour of the

find

function for the skip list:

I use a string as a key and integer as data.

the

find

function cannot find entries in the skip list, even if I create it with the

createString

.
Are there known issues with that?


SystemAdmin - Mon Feb 25 15:45:15 EST 2013

Re: Skip list "find" function
SystemAdmin - Tue Feb 26 03:31:19 EST 2013

Hi

Try
 

Skip skpSomeData = createString();
 
put(skpSomeData , "one", 1 "");

 


You cannot store an integer as an Skip-Data. You have to convert it into a string.

Best regards
Wolfgang

 

Re: Skip list "find" function
Tony_Goodman - Tue Feb 26 04:52:26 EST 2013

SystemAdmin - Tue Feb 26 03:31:19 EST 2013

Hi

Try
 

Skip skpSomeData = createString();
 
put(skpSomeData , "one", 1 "");

 


You cannot store an integer as an Skip-Data. You have to convert it into a string.

Best regards
Wolfgang

 

You CAN store integers in Skip data.
 

Skip s = createString
int i = 0
 
put(s, "one", 1)
put(s, "two", 2)
 
for i in s do
{
print (string key s) " " i "\n"
}
 
if (find(s, "one", i)) print i ""

 


Tony Goodman, www.smartdxl.com

 

Re: Skip list "find" function
SystemAdmin - Tue Feb 26 07:31:00 EST 2013

Tony_Goodman - Tue Feb 26 04:52:26 EST 2013

You CAN store integers in Skip data.
 

Skip s = createString
int i = 0
 
put(s, "one", 1)
put(s, "two", 2)
 
for i in s do
{
print (string key s) " " i "\n"
}
 
if (find(s, "one", i)) print i ""

 


Tony Goodman, www.smartdxl.com

 

Ups, you are right. I thought I've tested it and I it did not work.

Re: Skip list "find" function
SystemAdmin - Tue Feb 26 08:08:52 EST 2013

There is not strange behavior or reported issues with find. You do however have to implement find per the instructions in the help file.

Re: Skip list "find" function
llandale - Wed Feb 27 14:52:35 EST 2013

Tony is right.

It would be easier to debug if you specified what "strange" behavior, and posted the code.

-Louie

Re: Skip list "find" function
SystemAdmin - Mon Mar 04 05:59:26 EST 2013

SystemAdmin - Tue Feb 26 08:08:52 EST 2013
There is not strange behavior or reported issues with find. You do however have to implement find per the instructions in the help file.

ok, I was probably too short before. I do use find in a few routines and it looks like it works just fine exept one place, which makes me crazy, because on the first glance I impement it the usual way.

Here is the code of main part and the call:

Skip SWCNames = createString()
...all other definitions ...
 
 
ReadSystags(Systg_ptr,SWCNames,SWCi,io4sys_tags)


Here ist the function:
I have a problem with Skip list "SWCNames", whatever I put there, the "find" finds only the first repetitive entry the rest is alway not found, and the "put" command then returns false, because the key is already in the skip list.
I was supposing maybe it copies the reference to the buffer and made temp string, but no change in behavoir: the find works only once correct, wenn it finds first existing occurence in the skip list. The rest of the time it returns true whatever I pass to it.

 

bool ReadSystags(Module &Md_ptr, Skip &SWCNames,int &SWCi,Stream &io4dst_log)
{
    if(null Md_ptr) {
                io4dst_log << "ERRO : [DOORSER0001] : module is null or is not opened\n"
                return false
        }
        Object o = null
        Buffer tmp = create
        string SWC = ""
        int cur_SWCi=SWCi
        bool find_status = false
        for o in Md_ptr do
        {
                SWC = o."SWC - out"
                string stmp = ""
                stmp = SWC
                find_status = find(SWCNames,stmp,cur_SWCi)
                if(!find_status) //if found, sets SWCi to the id of the SWCName
                {
                        //if not found add new SWC and its id
                        cur_SWCi++
                        if(put(SWCNames,SWC "",cur_SWCi)) 
                        {io4dst_log << "cannot add new entry to the list of SWC names\n" } else { io4dst_log << "Ok\n"}
                } 
..... some more stuff .....
 
        }
        delete tmp
        SWCi=cur_SWCi
        return true
}

 

Re: Skip list "find" function
Mathias Mamsch - Mon Mar 04 07:18:08 EST 2013

SystemAdmin - Mon Mar 04 05:59:26 EST 2013

ok, I was probably too short before. I do use find in a few routines and it looks like it works just fine exept one place, which makes me crazy, because on the first glance I impement it the usual way.

Here is the code of main part and the call:

Skip SWCNames = createString()
...all other definitions ...
 
 
ReadSystags(Systg_ptr,SWCNames,SWCi,io4sys_tags)


Here ist the function:
I have a problem with Skip list "SWCNames", whatever I put there, the "find" finds only the first repetitive entry the rest is alway not found, and the "put" command then returns false, because the key is already in the skip list.
I was supposing maybe it copies the reference to the buffer and made temp string, but no change in behavoir: the find works only once correct, wenn it finds first existing occurence in the skip list. The rest of the time it returns true whatever I pass to it.

 

bool ReadSystags(Module &Md_ptr, Skip &SWCNames,int &SWCi,Stream &io4dst_log)
{
    if(null Md_ptr) {
                io4dst_log << "ERRO : [DOORSER0001] : module is null or is not opened\n"
                return false
        }
        Object o = null
        Buffer tmp = create
        string SWC = ""
        int cur_SWCi=SWCi
        bool find_status = false
        for o in Md_ptr do
        {
                SWC = o."SWC - out"
                string stmp = ""
                stmp = SWC
                find_status = find(SWCNames,stmp,cur_SWCi)
                if(!find_status) //if found, sets SWCi to the id of the SWCName
                {
                        //if not found add new SWC and its id
                        cur_SWCi++
                        if(put(SWCNames,SWC "",cur_SWCi)) 
                        {io4dst_log << "cannot add new entry to the list of SWC names\n" } else { io4dst_log << "Ok\n"}
                } 
..... some more stuff .....
 
        }
        delete tmp
        SWCi=cur_SWCi
        return true
}

 

I can guarantee you that the skip lists, the very core of DXL work as expected.

You might have a logical error in there. Let me rephrase what I read from the code:
 

  • Your ReadSystags fucntion reads the attribute value for the SWC - out attribute from the module
  • for each value it finds, it will create an Integer ID (SWCi) and store it to the skip, the first time it finds it.
  • When the function returns, it will return the last ID it has given (so not the next free one?)


If that is what you intended, the problem of your code seems to be, that you read the curSWI back from the skip:

 

...
find_status = find(SWCNames,SWC ,cur_SWCi)
...



The result of this, if you read the values "Hello", "World", "Hello", "New" is that



 

 

  • "Hello" gets cur_cur_SWCi= 0
  • "World" gets cur_cur_SWCi= 1
  • "Hello" is found and resets cur_SWCi -> 0
  • "New" gets cur_SWCi = 1 again ...


What also bothers me is that your log condition is inverted, it should have a ! (not) in front of it, because put will return true, when it puts the key in and false when the key already exists (which can never occur, since you have a the if find() { ... } block). So removing unnecessary redundany your code should look like this and be fine:

 

 

 

// You do not need to pass the skip as a reference, when you do not allocate it inside the function 
bool ReadSystags(Module &Md_ptr, Skip SWCNames,int &SWCi,Stream &io4dst_log)
{
    if(null Md_ptr) {
                io4dst_log << "ERRO : [DOORSER0001] : module is null or is not opened\n"
                return false
        }
 
        Object o = null
        Buffer tmp = create
        string SWC = ""
        int cur_SWCi=SWCi   // Good: You need to dereference the SWCi reference, before putting it in the skip
        bool find_status = false
        for o in Md_ptr do {  // Current Filter should be evaluated? 
                SWC = o."SWC - out"
                // Do not overwrite cur_SWCi here!?
                if( !find(SWCNames,SWC) ) {
                        cur_SWCi++
                        // put returns true if the item did not exist and could be added
                        if(! put(SWCNames, SWC, cur_SWCi) ) {
                            io4dst_log << "cannot add new entry to the list of SWC names\n" 
                        } else { 
                            io4dst_log << "Ok\n"
                        }
                } 
..... some more stuff .....
 
        }
        delete tmp
        SWCi = cur_SWCi
        return true
}



Hope that helps, regards, Mathias



 

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

Re: Skip list "find" function
SystemAdmin - Mon Mar 04 08:25:55 EST 2013

Mathias Mamsch - Mon Mar 04 07:18:08 EST 2013

I can guarantee you that the skip lists, the very core of DXL work as expected.

You might have a logical error in there. Let me rephrase what I read from the code:
 

  • Your ReadSystags fucntion reads the attribute value for the SWC - out attribute from the module
  • for each value it finds, it will create an Integer ID (SWCi) and store it to the skip, the first time it finds it.
  • When the function returns, it will return the last ID it has given (so not the next free one?)


If that is what you intended, the problem of your code seems to be, that you read the curSWI back from the skip:

 

...
find_status = find(SWCNames,SWC ,cur_SWCi)
...



The result of this, if you read the values "Hello", "World", "Hello", "New" is that



 

 

  • "Hello" gets cur_cur_SWCi= 0
  • "World" gets cur_cur_SWCi= 1
  • "Hello" is found and resets cur_SWCi -> 0
  • "New" gets cur_SWCi = 1 again ...


What also bothers me is that your log condition is inverted, it should have a ! (not) in front of it, because put will return true, when it puts the key in and false when the key already exists (which can never occur, since you have a the if find() { ... } block). So removing unnecessary redundany your code should look like this and be fine:

 

 

 

// You do not need to pass the skip as a reference, when you do not allocate it inside the function 
bool ReadSystags(Module &Md_ptr, Skip SWCNames,int &SWCi,Stream &io4dst_log)
{
    if(null Md_ptr) {
                io4dst_log << "ERRO : [DOORSER0001] : module is null or is not opened\n"
                return false
        }
 
        Object o = null
        Buffer tmp = create
        string SWC = ""
        int cur_SWCi=SWCi   // Good: You need to dereference the SWCi reference, before putting it in the skip
        bool find_status = false
        for o in Md_ptr do {  // Current Filter should be evaluated? 
                SWC = o."SWC - out"
                // Do not overwrite cur_SWCi here!?
                if( !find(SWCNames,SWC) ) {
                        cur_SWCi++
                        // put returns true if the item did not exist and could be added
                        if(! put(SWCNames, SWC, cur_SWCi) ) {
                            io4dst_log << "cannot add new entry to the list of SWC names\n" 
                        } else { 
                            io4dst_log << "Ok\n"
                        }
                } 
..... some more stuff .....
 
        }
        delete tmp
        SWCi = cur_SWCi
        return true
}



Hope that helps, regards, Mathias



 

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

Hi Mathias,

thanks for the prompt answer.

As to logical part:
yes, that is correct and intended, that I get the cur_SWCi back if the entry exists - i use it further in the part of code "...some more stuff...". I do have one more counter(which is not shown here), which holds the last id.

Yes, that is my typo with the inverted condition for "put" - this chunk of code was rewritten lot of times to understand the problem I have.

And after that the question still remains: why the "find" routine returns false for the existing entries in the skip list?
The funny thing about it is, if I use "create" instead of "createString" in the skip list init, I get expected behaviour, but invalid Id..

Nevertheless, I will try your implementation and give a feedback.

Alex.

Re: Skip list "find" function
llandale - Mon Mar 04 13:16:30 EST 2013

SystemAdmin - Mon Mar 04 05:59:26 EST 2013

ok, I was probably too short before. I do use find in a few routines and it looks like it works just fine exept one place, which makes me crazy, because on the first glance I impement it the usual way.

Here is the code of main part and the call:

Skip SWCNames = createString()
...all other definitions ...
 
 
ReadSystags(Systg_ptr,SWCNames,SWCi,io4sys_tags)


Here ist the function:
I have a problem with Skip list "SWCNames", whatever I put there, the "find" finds only the first repetitive entry the rest is alway not found, and the "put" command then returns false, because the key is already in the skip list.
I was supposing maybe it copies the reference to the buffer and made temp string, but no change in behavoir: the find works only once correct, wenn it finds first existing occurence in the skip list. The rest of the time it returns true whatever I pass to it.

 

bool ReadSystags(Module &Md_ptr, Skip &SWCNames,int &SWCi,Stream &io4dst_log)
{
    if(null Md_ptr) {
                io4dst_log << "ERRO : [DOORSER0001] : module is null or is not opened\n"
                return false
        }
        Object o = null
        Buffer tmp = create
        string SWC = ""
        int cur_SWCi=SWCi
        bool find_status = false
        for o in Md_ptr do
        {
                SWC = o."SWC - out"
                string stmp = ""
                stmp = SWC
                find_status = find(SWCNames,stmp,cur_SWCi)
                if(!find_status) //if found, sets SWCi to the id of the SWCName
                {
                        //if not found add new SWC and its id
                        cur_SWCi++
                        if(put(SWCNames,SWC "",cur_SWCi)) 
                        {io4dst_log << "cannot add new entry to the list of SWC names\n" } else { io4dst_log << "Ok\n"}
                } 
..... some more stuff .....
 
        }
        delete tmp
        SWCi=cur_SWCi
        return true
}

 

[1] Skip "find" searches for the KEY and (if found) returns that KEY's DATA.

string Key = "AA",
       Data = "DataForAA",
       DataInSkip = ""
if  (!find(skp, Key, DataInSkip))
then put (skp, Key, Data)
else print "Key " Key " already exists, data = " DataInSkip "\n"


Your code is trying to find the DATA using a null string KEY "stmp".

[2]YOU must also insure that the variable type for KEY and DATA are consistent between the "find" and the "put". Since I get very confused on that I always add this comment to my Skip lists:

- Skip skpMods = create()       // KEY: 'int' Sequence; DATA: 'string' NameModule
- Skip skpName = createString() // KEY and DATA: both 'string' NameModule


When my Skips are mis-behaving I display the declaration in one pane and search for the skip in the other, and make sure using the Skip is consistent with the declaration comment.

Putting one kind of info and Finding another is VooDoo understood by 5 folks in the world, I'm not one of them.

-Louie

 

Re: Skip list "find" function
SystemAdmin - Wed Mar 06 10:43:42 EST 2013

Mathias Mamsch - Mon Mar 04 07:18:08 EST 2013

I can guarantee you that the skip lists, the very core of DXL work as expected.

You might have a logical error in there. Let me rephrase what I read from the code:
 

  • Your ReadSystags fucntion reads the attribute value for the SWC - out attribute from the module
  • for each value it finds, it will create an Integer ID (SWCi) and store it to the skip, the first time it finds it.
  • When the function returns, it will return the last ID it has given (so not the next free one?)


If that is what you intended, the problem of your code seems to be, that you read the curSWI back from the skip:

 

...
find_status = find(SWCNames,SWC ,cur_SWCi)
...



The result of this, if you read the values "Hello", "World", "Hello", "New" is that



 

 

  • "Hello" gets cur_cur_SWCi= 0
  • "World" gets cur_cur_SWCi= 1
  • "Hello" is found and resets cur_SWCi -> 0
  • "New" gets cur_SWCi = 1 again ...


What also bothers me is that your log condition is inverted, it should have a ! (not) in front of it, because put will return true, when it puts the key in and false when the key already exists (which can never occur, since you have a the if find() { ... } block). So removing unnecessary redundany your code should look like this and be fine:

 

 

 

// You do not need to pass the skip as a reference, when you do not allocate it inside the function 
bool ReadSystags(Module &Md_ptr, Skip SWCNames,int &SWCi,Stream &io4dst_log)
{
    if(null Md_ptr) {
                io4dst_log << "ERRO : [DOORSER0001] : module is null or is not opened\n"
                return false
        }
 
        Object o = null
        Buffer tmp = create
        string SWC = ""
        int cur_SWCi=SWCi   // Good: You need to dereference the SWCi reference, before putting it in the skip
        bool find_status = false
        for o in Md_ptr do {  // Current Filter should be evaluated? 
                SWC = o."SWC - out"
                // Do not overwrite cur_SWCi here!?
                if( !find(SWCNames,SWC) ) {
                        cur_SWCi++
                        // put returns true if the item did not exist and could be added
                        if(! put(SWCNames, SWC, cur_SWCi) ) {
                            io4dst_log << "cannot add new entry to the list of SWC names\n" 
                        } else { 
                            io4dst_log << "Ok\n"
                        }
                } 
..... some more stuff .....
 
        }
        delete tmp
        SWCi = cur_SWCi
        return true
}



Hope that helps, regards, Mathias



 

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

I must admit, rebuilding the function "around" the code from Mathias helped.

I don't exactly understand where the problem was, but there's no problem with the skip list any more.

Re: Skip list "find" function
SystemAdmin - Wed Mar 06 10:50:15 EST 2013

Mathias Mamsch - Mon Mar 04 07:18:08 EST 2013

I can guarantee you that the skip lists, the very core of DXL work as expected.

You might have a logical error in there. Let me rephrase what I read from the code:
 

  • Your ReadSystags fucntion reads the attribute value for the SWC - out attribute from the module
  • for each value it finds, it will create an Integer ID (SWCi) and store it to the skip, the first time it finds it.
  • When the function returns, it will return the last ID it has given (so not the next free one?)


If that is what you intended, the problem of your code seems to be, that you read the curSWI back from the skip:

 

...
find_status = find(SWCNames,SWC ,cur_SWCi)
...



The result of this, if you read the values "Hello", "World", "Hello", "New" is that



 

 

  • "Hello" gets cur_cur_SWCi= 0
  • "World" gets cur_cur_SWCi= 1
  • "Hello" is found and resets cur_SWCi -> 0
  • "New" gets cur_SWCi = 1 again ...


What also bothers me is that your log condition is inverted, it should have a ! (not) in front of it, because put will return true, when it puts the key in and false when the key already exists (which can never occur, since you have a the if find() { ... } block). So removing unnecessary redundany your code should look like this and be fine:

 

 

 

// You do not need to pass the skip as a reference, when you do not allocate it inside the function 
bool ReadSystags(Module &Md_ptr, Skip SWCNames,int &SWCi,Stream &io4dst_log)
{
    if(null Md_ptr) {
                io4dst_log << "ERRO : [DOORSER0001] : module is null or is not opened\n"
                return false
        }
 
        Object o = null
        Buffer tmp = create
        string SWC = ""
        int cur_SWCi=SWCi   // Good: You need to dereference the SWCi reference, before putting it in the skip
        bool find_status = false
        for o in Md_ptr do {  // Current Filter should be evaluated? 
                SWC = o."SWC - out"
                // Do not overwrite cur_SWCi here!?
                if( !find(SWCNames,SWC) ) {
                        cur_SWCi++
                        // put returns true if the item did not exist and could be added
                        if(! put(SWCNames, SWC, cur_SWCi) ) {
                            io4dst_log << "cannot add new entry to the list of SWC names\n" 
                        } else { 
                            io4dst_log << "Ok\n"
                        }
                } 
..... some more stuff .....
 
        }
        delete tmp
        SWCi = cur_SWCi
        return true
}



Hope that helps, regards, Mathias



 

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

I have two questions regarding your comments, Mathias:

  • passing the skip list as reference or not, what the difference? Can I extend it on other types? I was always curious with the string, thinking doors makes copy of it, if I pass it not as a reference, and this copy stay in memory until the program ends.
  • what did you exactly mean with "Current filter should be evaluated?". Before the function call I make explicit
    filter off
    
    .

Re: Skip list "find" function
Mathias Mamsch - Wed Mar 06 16:27:31 EST 2013

SystemAdmin - Wed Mar 06 10:50:15 EST 2013

I have two questions regarding your comments, Mathias:

  • passing the skip list as reference or not, what the difference? Can I extend it on other types? I was always curious with the string, thinking doors makes copy of it, if I pass it not as a reference, and this copy stay in memory until the program ends.
  • what did you exactly mean with "Current filter should be evaluated?". Before the function call I make explicit
    filter off
    
    .

If you read my post again, the problem with your code was described there:

You restored your cur_SWCi on the find call. Usually you wanted to increase the cur_SWCi for each new value that has been found. So if you got the values:
 

Hello  (cur_SWCi = 1)
World  (cur_SWCi = 2)
Hello  (cur_SWCi = 1) <<-- find resets the curSWCi to 1
DXL (cur_SWCi = 2) <<-- here the next new value will get 2 instead of 3 ..

Passing a Skip by reference is only necessary if you want to reallocate it, not if you want to use it. Example:

 

void get123 (Skip &sk) {
   Skip deref = sk   // dereference for null check 
   if (null deref) sk = create() 
   put (sk, 1,1, true)
   put (sk, 2,2, true)
   put (sk, 3,3, true)
}
 
Skip sk = null
 
// since sk is passed by reference you reallocating it, will change the sk variable
// this would not happen if sk was passed by value
get123(sk)  
 
int i; if (find(sk, 1, i)) print "Found: 1->" i "\n"


Regarding your filter question: There is a couple of view settings, than influence the for Object in Module loop. Sorting, Table Cells of, Filtering, Level, etc. All these settings can have strange effects for your DXL with objects not showing up in the loop or in the right order. Therefore I would always use:

 

 

for o in entire mod do {
   if (isDeleted o) continue
   // if (cell o || row o || table o) continue   // depending if you want to take into account table cells
   ...
}


This way you have no surprises. Regards, Mathias

 

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

 

Re: Skip list "find" function
SystemAdmin - Thu Mar 07 04:50:54 EST 2013

Mathias Mamsch - Wed Mar 06 16:27:31 EST 2013

If you read my post again, the problem with your code was described there:

You restored your cur_SWCi on the find call. Usually you wanted to increase the cur_SWCi for each new value that has been found. So if you got the values:
 

Hello  (cur_SWCi = 1)
World  (cur_SWCi = 2)
Hello  (cur_SWCi = 1) <<-- find resets the curSWCi to 1
DXL (cur_SWCi = 2) <<-- here the next new value will get 2 instead of 3 ..

Passing a Skip by reference is only necessary if you want to reallocate it, not if you want to use it. Example:

 

void get123 (Skip &sk) {
   Skip deref = sk   // dereference for null check 
   if (null deref) sk = create() 
   put (sk, 1,1, true)
   put (sk, 2,2, true)
   put (sk, 3,3, true)
}
 
Skip sk = null
 
// since sk is passed by reference you reallocating it, will change the sk variable
// this would not happen if sk was passed by value
get123(sk)  
 
int i; if (find(sk, 1, i)) print "Found: 1->" i "\n"


Regarding your filter question: There is a couple of view settings, than influence the for Object in Module loop. Sorting, Table Cells of, Filtering, Level, etc. All these settings can have strange effects for your DXL with objects not showing up in the loop or in the right order. Therefore I would always use:

 

 

for o in entire mod do {
   if (isDeleted o) continue
   // if (cell o || row o || table o) continue   // depending if you want to take into account table cells
   ...
}


This way you have no surprises. Regards, Mathias

 

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

 

Hello Mathias,

thank you for the answers.

My comments, to your comments:

Actually, I use cur_SWCi the way I used it before - if the key is found in the skip list, cur_SWCi shall became the data of this key.
To track the IDs, there is one more variable. That is why I didn't exactly understand where the error was.
Passing Skip List as a reference: I am from the C/C++ world, so passing by reference means, I have acces to the data over the pointer. Passing by value means I copy the value to the subfunction. From your explanation I've got a feeling in dxl it works different.

Good Hint about filters - I will use it from now.

Re: Skip list "find" function
Mathias Mamsch - Thu Mar 07 06:40:57 EST 2013

SystemAdmin - Thu Mar 07 04:50:54 EST 2013
Hello Mathias,

thank you for the answers.

My comments, to your comments:

Actually, I use cur_SWCi the way I used it before - if the key is found in the skip list, cur_SWCi shall became the data of this key.
To track the IDs, there is one more variable. That is why I didn't exactly understand where the error was.
Passing Skip List as a reference: I am from the C/C++ world, so passing by reference means, I have acces to the data over the pointer. Passing by value means I copy the value to the subfunction. From your explanation I've got a feeling in dxl it works different.

Good Hint about filters - I will use it from now.

Regarding references: It works the same as in C/C++. If you for example take a struct like FILE in C/c++ and pass it by value to a function, than C/C++ will copy the whole object (i.e. all members) on the stack. So any change to the members inside a function will not have any effect on the original object.

However the FILE structure contains a lot of pointers and handles themselfes, e.g. buffers or file handles. Even though those pointers will be copied, they still point to the same location, that means, whenever you manipulate the FILE object, e.g. write some data to it, this data will of course be written to the same file.

The thing with DXL is, that ALL types in DXL (except the simple types), like Skip, Buffer are internally nothing more than a pointer to a DOORS internal data structure (there is one buggy exception which is the Range_ type, but more about that maybe in another post). So in C/C++ you would write:
 

struct Buffer {
   void *memory; 
}
 
struct Skip {
   void *memory;
}
 
...

That means, when you pass one of those types by value to a function, you are internally passing a pointer to the same memory. Therefore any function that operates on those types will modify the same internal data structure. So why would you ever want to pass one of those objects by reference? The only reason to do so, is if you want to reallocate the object. If you allocate a new Buffer from DXL:

 

Buffer buf = create()


Then a new internal Buffer structure will be allocated and a pointer to it will be assigned to the memory structure member of buf. If you do this inside a function with the buffer passed by value, then only the memory pointer of the copy will be changed, not of the original one. The original buffer variable will still point to the old buffer. If you pass the buffer by reference, then when reallocating it you will work on the original buffer structure and therefore the original buffer will then point to the newly allocated buffer.

Hope this clarifies things, regards, Mathias

 

 

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

 

Re: Skip list "find" function
Mark@V - Wed Jan 25 04:33:45 EST 2017

Tony_Goodman - Tue Feb 26 04:52:26 EST 2013

You CAN store integers in Skip data.
 

Skip s = createString
int i = 0
 
put(s, "one", 1)
put(s, "two", 2)
 
for i in s do
{
print (string key s) " " i "\n"
}
 
if (find(s, "one", i)) print i ""

 


Tony Goodman, www.smartdxl.com

 

You CAN also use integers as a key in a skip list if you (postpend ??) them with ""

Skip s = createString
int i = 0
 
print (put(s, 0 "", 1)) "\n"
print (put(s, 1 "", 2)) "\n"
 
for i in s do
{
print (string key s) " " i "\n"
}
 
if (find(s, "one", i)) print i ""

 

Re: Skip list "find" function
Mike.Scharnow - Wed Jan 25 14:09:28 EST 2017

Mark@V - Wed Jan 25 04:33:45 EST 2017

You CAN also use integers as a key in a skip list if you (postpend ??) them with ""

Skip s = createString
int i = 0
 
print (put(s, 0 "", 1)) "\n"
print (put(s, 1 "", 2)) "\n"
 
for i in s do
{
print (string key s) " " i "\n"
}
 
if (find(s, "one", i)) print i ""

 

yes, of course, but why would you want to do that?

When you design a skip list, the outcome of your design should be the types of your key and data. You will program all functions using this skip list with the design in mind.

If you have a Skip list which uses integers as key, you will create the list using "skMySkip = create()", if the keys are strings, you will do "skMySkip = createString()".

To answer my question: Well, you might want to program generic functions that work on all skip lists and to ease work, you decide that all skip lists have strings as key. But whether this design is really useful depends on your requirements...